package de.gameduell.net.src.body {

	import de.gameduell.net.src.encryption.IEncryption;
	import de.gameduell.net.src.hashing.IHashing;
	
	public class Body_V2 implements IBody{

		private const DELIMITER:String = "\t";
		
		private var _requestType:String;
		private var _parameters:Array;
		private var _content:String;
		private var _hashing:IHashing;
		private var _encryption:IEncryption;

		public function Body_V2(aRequestType:String,aParameters:Array,aHashing:IHashing,aEncryption:IEncryption) {
			_requestType = aRequestType;
			parameters   = aParameters;
			_hashing	 = aHashing;
			_encryption  = aEncryption;
			createContent(aParameters);		
		}
		
		public function get content():String {
			return _content;
		}
		
		public function get encryptedContent():String {		
			return _encryption.encrypt(hashCode+DELIMITER+_content);
		}
		
		public function get requestType():String {
			return _requestType;
		}
		
		public function get hashCode():String {
			return _hashing.hash(_content);
		}
		
		public function set parameters(aParameters:Array):void {
			_parameters = aParameters;
			createContent(aParameters);
		}
		
		public function get parameters():Array {
			return _parameters;
		}
		
		public function createContent(aParameters:Array):void{
			if(aParameters.length > 0){
				_content = _requestType + DELIMITER + _parameters.join(DELIMITER);
			}else{
				_content = _requestType;
			}
		}
	}
}
